package com.zd01.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.UUID;


@RestController
@Slf4j
public class UpLoadController  {
    @PostMapping("/upload")
    public String uploadFile (String name,MultipartFile file) throws IOException {
        log.info("上传文件名称：{}",name);
        log.info("上传文件名称：{}",file.getOriginalFilename());

        //将文件保存到本地
        String fileName = file.getOriginalFilename();
        // 文件后缀名
        String suffixName = fileName.substring(fileName.lastIndexOf("."));
        // uuid
       String uuid = UUID.randomUUID().toString();
       String newFileName = uuid + suffixName;
       file.transferTo(new File("/Users/zd/IJavaProjects/zd01/src/main/resources/static/"+newFileName));
       return "success";
    }


}
